﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Push.Entities;

namespace Push
{
	public partial class Disc : UserControl
	{
        public DiscEntity discEntity { get; set; }

        public Disc()
        {
        
        }

        public Disc(DiscColor discColor, double radius, int ID, bool CreateEntity)
		{
            InitializeComponent();

            this.IsHitTestVisible = false;

            if (CreateEntity)
            {
                discEntity = new DiscEntity(this) { ID = ID, Radius = radius };
            }

            ChangeColor(discColor);
            ChangeRadius(radius);
		}

        public void ChangeColor(DiscColor discColor)
        {
            discEntity.discColor = discColor;

            switch (discColor)
            {
                case DiscColor.Yellow:
                {
                    disc.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));
                    break;
                }
                case DiscColor.Red:
                {
                    disc.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                    break;
                }
                case DiscColor.Blue:
                {
                    disc.Fill = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255));
                    break;
                }
            }
        }

        public void ChangeRadius(double radius)
        {
            discEntity.Radius = radius;

            double radius_2 = radius * 2;
            outline.Width = radius_2;
            outline.Height = radius_2;
            double inner_radius_2 = 0.9 * radius_2 - 3;
            disc.Width = inner_radius_2;
            disc.Height = inner_radius_2;
        }

        public void ChangeState(DiscState state)
        {
            if (discEntity.State == DiscState.InGame && state == DiscState.Waited)
            {
                ChangeRadius(discEntity.Radius / 5.0);
            }
            else if (discEntity.State == DiscState.Waited && state == DiscState.InGame)
            {
                ChangeRadius(discEntity.Radius * 5.0);
            }

            discEntity.State = state;
        }
	}

    public enum DiscColor
    {
        Yellow,
        Red,
        Blue
    }

    public enum DiscState
    {
        Waited,
        InGame
    }
}